#include "CCMySprite.h"
#include "cocos2d.h"

CCMySprite::CCMySprite(void)
{
	lifeTime = 0;
	isCCFinished = false;
}


CCMySprite::~CCMySprite(void)
{
}


void CCMySprite::setMyNotification(cocos2d::CCLabelTTF* value){
	myNotification = value;
}
cocos2d::CCLabelTTF* CCMySprite::getMyNotification(){
	return myNotification;
}

void CCMySprite::setBlood(float value){
	blood = value;
}
float CCMySprite::getBlood(){
	return blood;
}
void CCMySprite::setIsAnimationFinished(bool is){
	isAnimationFinished = is;
}

bool CCMySprite::getIsAnimationFinished(){
	return isAnimationFinished;
}

void CCMySprite::setSpSheetArray(cocos2d::CCArray* spSheetArr)
{
	spSheetArray = spSheetArr;
}
cocos2d::CCArray* CCMySprite::getSpSheetArray(){
	return spSheetArray;
}
void CCMySprite::setBacthNodeSheetArr(cocos2d::CCArray* arr){
	batchNodeSheetArr = arr;
}
cocos2d::CCArray* CCMySprite::getBacthNodeSheetArr(){
	return batchNodeSheetArr;
}
void CCMySprite::setFileName(cocos2d::CCString* name)
{
	fileName = name;
}

void CCMySprite::setPreviousPosition(cocos2d::CCPoint pos)
{
	previousPosition = ccp(pos.x,pos.y);
}
cocos2d::CCPoint CCMySprite::getPreviousPosition()
{
	return previousPosition;
}

int CCMySprite::getRandomNum(int max,int min)
{
	return rand()%(max-min + 1) + min;
}
void CCMySprite::setID(int i)
{
	_id = i;
}
int CCMySprite::getID()
{
	return _id;
}

void CCMySprite::setLifeTime(float time)
{
	lifeTime = time;
}
float CCMySprite::getLifeTime()
{
	return lifeTime;
}

CCMySprite* CCMySprite::createWithTexture(cocos2d::CCTexture2D *pTexture)
{
	CCMySprite* sp;
	sp = new CCMySprite();
	sp->initWithTexture(pTexture);
	sp->autorelease();
	return sp;
}

CCMySprite* CCMySprite::create(const char *pszFileName)
{
	CCMySprite* sp = new CCMySprite();
	sp->initWithFile(pszFileName);
	sp->autorelease();
	return sp;
}
CCMySprite* CCMySprite::create()
{
	CCMySprite* sp = new CCMySprite();
	sp->autorelease();
	sp->init();
	return sp;
}
void CCMySprite::doScaleEffect(float iDruration,float scaleNumX,float scaleNumY,int iTimes)
{
	float oldScaleX = this->getScaleX();
	float oldScaleY = this->getScaleY();
	cocos2d::CCScaleTo *sca1 = cocos2d::CCScaleTo::create(iDruration,scaleNumX,scaleNumY);
	cocos2d::CCScaleTo *sca2 = cocos2d::CCScaleTo::create(iDruration,oldScaleX,oldScaleY);
	cocos2d::CCSequence *seqScale = cocos2d::CCSequence::create(sca1,sca2,NULL);
	if(iTimes==0)
	{
		this->runAction(cocos2d::CCRepeatForever::create(seqScale));
	}else
	{
		this->runAction(cocos2d::CCRepeat::create(seqScale,iTimes));
	}
}
void CCMySprite::doShakingEffect(float iDuration,float fAngle,int iTimes)
{
	float rot = this->getRotation();
	cocos2d::CCRotateTo* rotL = cocos2d::CCRotateTo::create(iDuration,rot + -fAngle);
	cocos2d::CCRotateTo* rotC = cocos2d::CCRotateTo::create(iDuration,0 + rot) ;
	cocos2d::CCRotateTo* rotR = cocos2d::CCRotateTo::create(iDuration,rot + fAngle);
	cocos2d::CCSequence* seq = cocos2d::CCSequence::create(rotL, rotC, rotR,rotC, NULL);
	if(iTimes==0)
	{
		this->runAction(cocos2d::CCRepeatForever::create(seq));
	}else
	{
		this->runAction(cocos2d::CCSequence::create(cocos2d::CCRepeat::create(seq,iTimes),NULL));
	}
}
void CCMySprite::doRotate360Effect(float iDuration,int iTimes)
{
	cocos2d::CCRotateTo *rotL = cocos2d::CCRotateTo::create(iDuration/2,180);
	cocos2d::CCRotateTo *rotR = cocos2d::CCRotateTo::create(iDuration/2, 360);
	cocos2d::CCRotateTo *rotB = cocos2d::CCRotateTo::create(0, 0);
	cocos2d::CCSequence *seq = cocos2d::CCSequence::create(rotL, rotR, rotB,NULL);
	this->runAction(cocos2d::CCRepeat::create(seq, iTimes));
}
void CCMySprite::doRotate360Effect(float iDuration)
{
	cocos2d::CCRotateTo *rotL = cocos2d::CCRotateTo::create(iDuration,180);
	cocos2d::CCRotateTo *rotR = cocos2d::CCRotateTo::create(iDuration,360);
	cocos2d::CCSequence *seq = cocos2d::CCSequence::create(rotL, rotR, NULL);
	this->runAction(cocos2d::CCRepeatForever::create(seq));
}
